package com.zm.demo.dubbo.consumer;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.zm.demo.dubbo.sc.api.UserService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.PropertySource;

import javax.annotation.PostConstruct;
import java.io.IOException;

/**
 * @author zoum
 * @create 2019/4/28 17:31
 */

@EnableDubbo
@PropertySource(value = "classpath:application.properties")
public class Application {

    @Reference(generic = true, interfaceClass = com.zm.demo.dubbo.sc.api.UserService.class)
    private GenericService userService;

    @PostConstruct
    public void init(){
        for (int i = 0 ; i < 10 ; i++) {
//            System.out.println(userService.hello("zm" + i));
            System.out.println(userService.$invoke("hello", new String[]{"java.lang.String"}, new String[]{"genericService " + i}));
        }
    }

    public static void main(String[] args) throws IOException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(Application.class);
        context.refresh();
        context.close();
    }
}
